package com.txunda.zhuohired.aty.manage.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ants.theantsgo.util.L;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.smarttop.library.bean.City;
import com.smarttop.library.bean.County;
import com.smarttop.library.bean.Province;
import com.smarttop.library.bean.Street;
import com.smarttop.library.utils.LogUtil;
import com.smarttop.library.widget.AddressSelector;
import com.smarttop.library.widget.BottomDialog;
import com.smarttop.library.widget.OnAddressSelectedListener;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/13 9:20
 * 功能描述：选择工作地点
 * 联系方式：jiahuanchen@126.com
 */

public class SelectJobAddressAty extends BaseAty  implements AddressSelector.onSelectorAreaPositionListener,
        OnAddressSelectedListener, AddressSelector.OnDialogCloseListener{
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * 保存
     */
    @ViewInject(R.id.tv_layout_white_right)
    private TextView tv_layout_white_right;
    /**
     * 城市
     */
    @ViewInject(R.id.tv_select_job_address)
    private TextView tv_select_job_address;

    private BottomDialog dialog;
    private int provincePosition;
    private int cityPosition;
    private int countyPosition;
    private int streetPosition;
    private String provinceCode;
    private String cityCode;
    private String countyCode;
    private String streetCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("工作地点");
        tv_layout_white_right.setVisibility(View.VISIBLE);
        tv_layout_white_right.setText("保存");
    }

    @Override
    @OnClick({R.id.ll_select_job_address,R.id.tv_layout_white_right})
    public void onClick(View v) {
        super.onClick(v);
        switch(v.getId()){
            case R.id.ll_select_job_address://选择城市
                if (dialog != null) {
                    dialog.show();
                } else {
                    dialog = new BottomDialog(this);
                    dialog.setOnAddressSelectedListener(this);
                    dialog.setDialogDismisListener(this);
                    dialog.setTextSize(14);//设置字体的大小
                    dialog.setIndicatorBackgroundColor(android.R.color.holo_orange_light);//设置指示器的颜色
                    dialog.setTextSelectedColor(android.R.color.holo_orange_light);//设置字体获得焦点的颜色
                    dialog.setTextUnSelectedColor(android.R.color.holo_blue_light);//设置字体没有获得焦点的颜色
                    //            dialog.setDisplaySelectorArea("31",1,"2704",1,"2711",0,"15582",1);//设置已选中的地区
                    dialog.setSelectorAreaPositionListener(this);
                    dialog.show();
                }
                break;
            case R.id.tv_layout_white_right://保存

                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_select_job_address;
    }

    @Override
    protected void initialized() {

    }

    @Override
    protected void requestData() {

    }

    @Override
    public void selectorAreaPosition(int provincePosition, int cityPosition, int countyPosition, int streetPosition) {
        this.provincePosition = provincePosition;
        this.cityPosition = cityPosition;
        this.countyPosition = countyPosition;
        this.streetPosition = streetPosition;
        LogUtil.d("数据", "省份位置=" + provincePosition);
        LogUtil.d("数据", "城市位置=" + cityPosition);
        LogUtil.d("数据", "乡镇位置=" + countyPosition);
        LogUtil.d("数据", "街道位置=" + streetPosition);
    }

    @Override
    public void onAddressSelected(Province province, City city, County county, Street street) {
        provinceCode = (province == null ? "" : province.code);
        cityCode = (city == null ? "" : city.code);
        countyCode = (county == null ? "" : county.code);
        streetCode = (street == null ? "" : street.code);
        L.e("=================", "省份id=" + provinceCode);
        L.e("=================", "城市id=" + cityCode);
        L.e("=================", "乡镇id=" + countyCode);
        L.e("=================", "街道id=" + streetCode);
        String s = (province == null ? "" : province.name) + (city == null ? "" : city.name) + (county == null ? "" :
                county.name) +
                (street == null ? "" : street.name);
        L.e("=================", s);
        tv_select_job_address.setText(s);
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    @Override
    public void dialogclose() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }

}
